﻿@using Apps.Web.Core;
@using Apps.Common;
@using Apps.Models.Sys;
@using Apps.Locale;
@{
    ViewBag.Title = "Index";
    Layout = "~/Views/Shared/_Index_Layout.cshtml";
    List<permModel> perm = null;
}
<div class="mvctool">

<div class="mvctool">
   @Html.ToolButton("btnCreate", "fa fa-plus", Resource.Create,ref perm, "Create", true)
   @Html.ToolButton("btnEdit", "fa fa-pencil", Resource.Edit,ref perm, "Edit", true)
   @Html.ToolButton("btnDelete", "fa fa-trash", Resource.Delete,ref perm, "Delete", true)
    @Html.ToolButton("btnEnable", "fa fa-search", "启用", ref perm, "Edit", true)
    @Html.ToolButton("btnDisable", "fa fa-search", "禁用", ref perm, "Edit", true)
</div>
</div>
<table id="List"></table>

<div id="modalwindow" class="easyui-window" data-options="modal:true,closed:true,minimizable:false,shadow:false"></div>
@Html.Partial("~/Views/Shared/_Partial_AutoGrid.cshtml")
<script type="text/javascript">
    $(function () {
        $('#List').treegrid({
            url: '@Url.Action("GetList")',
            width:  SetGridWidthSub(10),
            methord: 'post',
            height: SetGridHeightSub(45),
            fitColumns: true,
            treeField: 'Name',
            idField: 'Id',
            pagination: false,
            striped: true, //奇偶行是否区分
            singleSelect: true,//单选模式
            rownumbers: true,//行号
            onLoadSuccess: function (data) {
                $('#List').treegrid("select", 0);
                var row = $('#List').treegrid('getSelected');
                if (row != null) {
                    if (row.Enable) {
                        $("#btnEnable").hide();
                        $("#btnDisable").show();
                    }
                    else {
                        $("#btnDisable").hide();
                        $("#btnEnable").show();
                    }
                }
            },
            columns: [[
                { field: 'Id', title: '@Resource.TitleID', width: 50,hidden:true },
                { field: 'Name', title: '@Resource.TitleName', width: 80 },
                { field: 'ParentId', title: '上级ID', width: 50, hidden: true },
                { field: 'Sort', title: '@Resource.TitleSort', width: 30 },
                {
                    field: 'Enable', title: '@Resource.TitleEnable', width: 30, align: 'center', formatter: function (value) { return EnableFormatter(value) }
                },
                { field: 'Remark', title: '@Resource.TitleRemark', width: 80 },
                { field: 'CreateTime', title: '@Resource.TitleCreateTime', width: 80 }
            ]], onClickRow: function (row) {
                if (row.Enable) {
                    $("#btnEnable").hide();
                    $("#btnDisable").show();
                }
                else {
                    $("#btnDisable").hide();
                    $("#btnEnable").show();
                }

            }
        });
    });
    //ifram 返回
    function frameReturnByClose() {
        $("#modalwindow").window('close');
    }
    function frameReturnByReload(flag) {
        if (flag)
            $("#List").treegrid('reload');
        else
            $("#List").treegrid('load');
    }
    $("#btnEnable,#btnDisable").click(function () {
        var row = $('#List').treegrid('getSelected');
        if (row != null) {
            $.messager.confirm(index_lang_tip, '您确定对此状态进行更改?', function (r) {
                if (r) {
                    $.post("@Url.Action("ChangeState")?Id=" + row.Id, function (data) {
                        if (data.type == 1) {
                            $("#List").treegrid('load');
                            var row1 = $('#List').treegrid('getSelected');
                            if (row1 != null) {
                                if (row1.Enable) {
                                    $("#btnEnable").show();
                                    $("#btnDisable").hide();
                                }
                                else {
                                    $("#btnEnable").hide();
                                    $("#btnDisable").show();
                                }
                            }
                        }
                        $.messageBox5s(Lang.Tip, data.message);
                    }, "json");
                }
            });
        } else { $.messageBox5s(Lang.Tip, '@Resource.PlaseChooseToOperatingRecords'); }
    });
    function frameReturnByMes(mes) {
        $.messageBox5s('@Resource.Tip', mes);
    }
    $(function () {

        $("#btnCreate").click(function () {
            var row = $('#List').treegrid('getSelected');
            if (row && row != "" && row != "Id") {
                $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0'' src='/SysStruct/Create?id=" + (row != null ? row.Id : "0") + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Create', width: 700, height: 400, iconCls: 'fa fa-plus' }).window('open');
            } else {
                $.messageBox5s('@Resource.Tip', '请先选择一个上级部门');
            }
        });
        $("#btnEdit").click(function () {
            var row = $('#List').treegrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='100%'  frameborder='0' src='/SysStruct/Edit?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Edit', width: 700, height: 430, iconCls: 'fa fa-pencil' }).window('open');
            } else { $.messageBox5s('@Resource.Tip', '@Resource.PlaseChooseToOperatingRecords'); }
        });
        $("#btnDetails").click(function () {
            var row = $('#List').treegrid('getSelected');
            if (row != null) {
                $("#modalwindow").html("<iframe width='100%' height='100%' scrolling='no' frameborder='0' src='/SysStruct/Details?id=" + row.Id + "&Ieguid=" + GetGuid() + "'></iframe>");
                $("#modalwindow").window({ title: '@Resource.Details', width: 500, height: 300, iconCls: 'fa fa-list' }).window('open');
            } else { $.messageBox5s('@Resource.Tip', '@Resource.PlaseChooseToOperatingRecords'); }
        });

        $("#btnDelete").click(function () {
            var row = $('#List').treegrid('getSelected');
            if (row != null) {
                $.messager.confirm('@Resource.Tip', '@Resource.YouWantToDeleteTheSelectedRecords', function (r) {
                    if (r) {
                        $.post("@Url.Action("Delete")?id=" + row.Id, function (data) {
                            if (data.type == 1)
                                $("#List").treegrid('reload');
                            $.messageBox5s('@Resource.Tip', data.message);
                        }, "json");

                    }
                });
            } else { $.messageBox5s('@Resource.Tip', '@Resource.PlaseChooseToOperatingRecords'); }
        });
    });
</script>
